<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
<script>
    // 简洁语法
    const [max, min] = [1, 2]

    let a = 10;
    let b = 20;
    [a, b] = [b, a];
    console.log(a)
    console.log(b)
    
    const [c, d, ...e] = [10 , 20, 30 ,40] // 10 20 [30, 40]
    const [f = 0, g = 0] = []   // 默认值
    const [h, i, , ,j] = [10 , 20, 30 ,40]  // 按需赋值
    const arr = [1, 2, [3, 4]]  // arr[2][0] = 3 // 多维数组




    const {name, password} = {
        name : 'dcj',
        password : 123
    }   // const name = user.name
    // 变量名重新改名
    const {uname: username, password: pwd} = {
        uname : 'dcj',
        password: 123
    }   // const username = obj.uname
    // const pwd = obj.password


    // 数组对象解构
    const [{name : uname, age}] = [{
        name : 'dcj',
        age : 26
    },{
        name : 'lop',
        age : 26
    }
    ]
    console.log(uname)  // dcj

    // 多级对象解构
    const {name: aname, habbits: {hh}} = {
        name : '',
        habbits : {
            hh: 123 
        }
    }
</script>
    
</body>
</html>